package code.structure.module.friends.view
{
	import com.greensock.TweenLite;
	import com.patience.mvc.context.Command;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import code.structure.manager.loader.DllLoaderManager;
	import code.structure.manager.pop.view.Panel;
	import code.structure.module.friends.FriendsController;
	import code.untils.CommandNameConst;
	import code.untils.SWFNameConst;
	
	/**
	 * 好友列表
	 * @author CYoung
	 * 2014-7-15下午9:55:12
	 */
	public class FriendsView extends Panel
	{
		private var _view:Sprite; //好友列表模块的主界面
		
		private var _functionArea:Sprite; //功能区
		private var _diyArea:Sprite;	//diy按钮区
		
		private var _isDIY:Boolean; //当前是否在DIY状态
		
		private var _controller:FriendsController;
		public function set controller(value:FriendsController):void { _controller = value; }

		
		public function FriendsView(controller:FriendsController)
		{
			_controller = controller;
		}
		
		override protected function initializePanel():void
		{
			_view = new (DllLoaderManager.getInstance().getUIMaterial(SWFNameConst.FRIENDS_PANEL, "FriendsBar") as Class)() as Sprite;
			_functionArea = _view.getChildByName("mc_function") as Sprite;
			_diyArea = _view.getChildByName("mc_diy") as Sprite;
			_functionArea.addEventListener(MouseEvent.CLICK, mouseClick);
			_diyArea.addEventListener(MouseEvent.CLICK, mouseClick);
			_mMain.addChild(_view);
		}
		
		//鼠标点击按钮处理
		private function mouseClick(e:MouseEvent):void
		{
			switch(e.target.name) {
				case "btn_move":
					_controller.dispatch(new Command(CommandNameConst.COMMAND_MOVE_MAP_GOODS));
					break;
				case "btn_rotation":
					_controller.dispatch(new Command(CommandNameConst.COMMAND_ROTATION_MAP_GOODS));
					break;
				case "btn_recover":
					_controller.dispatch(new Command(CommandNameConst.COMMAND_RECOVER_MAP_GOODS));
					break;
				case "btn_diy":
					_isDIY == true?exitDIY(true):enterDIY(true);
					break;
				case "btn_shop":
					_controller.dispatch(new Command(CommandNameConst.COMMAND_SHOW_SHOP));
					break;
				case "btn_bag":
					
					break;
			}
		}
		//进入DIY
		private function enterDIY(dispatch:Boolean):void{
			var offx:int = _view.width/2 - _diyArea.width*2;
			TweenLite.to(_diyArea, 0.3, {x:offx});
			if(dispatch) _controller.dispatch(new Command(CommandNameConst.COMMAND_ENTER_DIY_EDIT));
			_isDIY = true;
		}
		//退出DIY
		private function exitDIY(dispatch:Boolean):void{
			var offx:int = _view.width/2 - _diyArea.width;
			TweenLite.to(_diyArea, 0.2, {x:offx});
			if(dispatch) _controller.dispatch(new Command(CommandNameConst.COMMAND_CONFIRM_EDIT));
			_isDIY = false;
		}
		
		public function set data(value:Array):void
		{
			
		}
	}
}